import org.junit.Test;

import java.util.concurrent.locks.LockSupport;

/**
 * @Author: mazhongqing
 * @Date: 2020/10/19 20:15
 */
public class LockSupportDemo {
    Thread t1,t2;

    @Test
    public void demo(){
        char[] aI = "123456".toCharArray();
        char[] aC = "abcdef".toCharArray();

        t1 = new Thread(()->{
            for(char c:aI){
                System.out.print(c);
                LockSupport.unpark(t2);
                LockSupport.park();
            }
        });

        t2 = new Thread(()->{
           for(char c:aC){
               LockSupport.park();
               System.out.print(c);
               LockSupport.unpark(t1);
           }
        });

        t1.start();
        t2.start();
    }
}
